package com.blb.article_ms.controller;

import com.blb.article_ms.entity.ResponseResult;
import com.blb.article_ms.util.OssUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@CrossOrigin
@RestController
public class UploadController {

    @RequestMapping("/upload")
    public ResponseResult<String> upload(MultipartFile file) throws IOException {
        OssUtil.upload(file.getInputStream(),file.getOriginalFilename());
        String url = OssUtil.getURL(file.getOriginalFilename());
        return ResponseResult.ok(url);
    }
}
